const myNew = function (constructor) {
  const obj = {};
  const args = Array.prototype.slice.call(arguments, 1);
  const result = constructor.apply(obj, args);
  obj.__proto__ = constructor.prototype;

  if (typeof result === 'object' && typeof result !== null) {
    return result;
  }

  return obj;
};

function Person(name) {
  this.name = name;
}

Person.prototype.say = () => {
  console.log('hello world');
};

const person = myNew(Person, 'name');
console.log(person.name);
console.log(person.say);
